package sonic.game.item;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import sonic.game.animation.Animation;
import sonic.game.character.Sonic;
import sonic.game.tile.Tile;
import sonic.game.util.Vector2D;

/**
 * GameItemRing
 * 
 * Standard collectible ring
 * 
 * @author Richard Greenlees
 *
 */

public class GameItemRing extends GameItem {


	public GameItemRing(Vector2D startLoc)
	{
		super(startLoc);
		
		collisionType = eCollisionType.CT_TOUCHALL;
		
		try
		{
			BufferedImage idleAnim1;
			BufferedImage idleAnim2;
			BufferedImage idleAnim3;
			idleAnim1 = ImageIO.read(new File("Items/Ring_idle_1.png"));
			idleAnim2 = ImageIO.read(new File("Items/Ring_idle_2.png"));
			idleAnim3 = ImageIO.read(new File("Items/Ring_idle_3.png"));
			
			idleAnim = new Animation(0.5f, idleAnim1, idleAnim2, idleAnim3);
			currentAnim = idleAnim;
		}
		catch (IOException e)
		{
			e.printStackTrace();
			destroy();
		}
		collisionBoxX = 16.0f;
		collisionBoxY = 16.0f;
		updateBounds();
		
	}
	
	public void touch(Tile toucher)
	{
		// Ignore all touches except Sonic. Give ring, play collect effect and sound then disappear forever
		if (toucher instanceof Sonic)
		{
			((Sonic) toucher).rings++;
			createEffect(location.x, location.y, new Animation(0.25f, false, "Effects/Ring_collect_1.png", "Effects/Ring_collect_2.png", "Effects/Ring_collect_3.png"));
			playSound("sounds/Ring_collect.wav");
			destroy();
		}
	}
}
